﻿;-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-*2013*-
;
;HHS-SCIENCE-OLYMPIAD-2013-ROBOT-ARM-CONTROL-AHK-MAESTRO-CONTROL
;Version		: 1.0.3.1
;Authors		: Bryant Grey-Stewart (Mobius1), David "Pringles" Fellows (Bohr)
;Release Notes	: 

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;Possition Variables: Storing the current possitions of the servos
baseTarg = 4500
sholTarg = 4500
elboTarg = 4500
;wrisTarg = 4500
gripTarg = 4500

;Increment Variables: Determines the rate at which the servos on the robot move
baseRate = 200
sholRate = 200
elboRate = 200
;wrisRate = 200
gripRate = 200
 
;Pin Variables: Which Slot are the parts in anyways
baseServo = 10
sholServo = 11
elboServo = 9
;wrisServo = 7
gripServo = 8
 
;Lmit Variables: Define the minimum and maximum ranges of the servos
minBasePos = 700
minSholPos = 800
minElboPos = 600
;minWrisPos = 600
minGripPos = 1100
 
maxBasePos = 9200
maxSholPos = 6800
maxElboPos = 9600
;maxWrisPos = 9600aa
maxGripPos = 9600

;State Variables: Store the State of the Robot
servoSpeedLimitsSet = 0

;Initializations, These will set the Servo 
!i::
if (servoSpeedLimitSet < 1)
{
	RunWait usccmd --speed %baseServo%`,45,,Hide
	RunWait usccmd --speed %sholServo%`,45,,Hide
	RunWait usccmd --speed %elboServo%`,45,,Hide
	;RunWait usccmd --speed %wrisServo%`,45,,Hide
	RunWait usccmd --speed %gripServo%`,45,,Hide
	servoSpeedLimitSet = 1
	;MsgBox %servoSpeedLimitSet%
}
else
{
	RunWait usccmd --speed %baseServo%`,0,,Hide
	RunWait usccmd --speed %sholServo%`,0,,Hide
	RunWait usccmd --speed %elboServo%`,0,,Hide
	;RunWait usccmd --speed %wrisServo%`,45,,Hide
	RunWait usccmd --speed %gripServo%`,45,,Hide
	servoSpeedLimitSet = 0
	;MsgBox %servoSpeedLimitSet%
}
return

;Controls : All COntrol Hot Keys are here
;Refer to included mappiong guide for keymappings
;


;BASE CONTROL
;
;Move Base Right (Toward Max)
	!d::
	if (baseTarg < maxBasePos) ; if target is within limts
	{
		baseTarg := baseTarg + baseRate ; add movement to target
		RunWait usccmd --servo %baseServo%`,%baseTarg%,,Hide ;Go there and close cmd
	}
	return

;Move Base Left (Toward Min)
	!a::
	if (baseTarg > minBasePos)
	{
		baseTarg := baseTarg - baseRate
		RunWait usccmd --servo %baseServo%`,%baseTarg%,,Hide
	}
	return


;SHOLDER CONTROL
;
;Move Shol Up (Toward Max)
	!w::
	if (sholTarg < maxSholPos)
	{
		sholTarg := sholTarg + sholRate
		RunWait usccmd --servo %sholServo%`,%sholTarg%,,Hide
	}
	return

;Move Shol Down (Toward Min)
	!s::
	if (sholTarg > minSholPos)
	{
		sholTarg := sholTarg - sholRate
		RunWait usccmd --servo %sholServo%`,%sholTarg%,,Hide
	}
	return


;ELBOW CONTROL
;
;Move Elbo Down (Toward Max)
	!j::
	if (elboTarg < maxElboPos)
	{
		elboTarg := elboTarg + elboRate
		RunWait usccmd --servo %elboServo%`,%elboTarg%,,Hide
	}
	return

;Move Elbo Up (Toward Min)
	!u::
	if (elboTarg > minElboPos)
	{
		elboTarg := elboTarg - elboRate
		RunWait usccmd --servo %elboServo%`,%elboTarg%,,Hide
	}
	return


;WRIST CONTROL
;
;Move Wris Up (Toward Max)
	!h::
	if (wrisTarg < maxWrisPos)
	{
		wrisTarg := wrisTarg + wrisRate
		RunWait usccmd --servo %wrisServo%`,%wrisTarg%,,Hide
	}
	return

;Move Wris Down (Toward Min)
	!k::
	if (wrisTarg > minWrisPos)
	{
		wrisTarg := wrisTarg - wrisRate
		RunWait usccmd --servo %wrisServo%`,%wrisTarg%,,Hide
	}
	return


;GRIPPER CONTROL
;
;Move Grip Open (Toward Max)
	!r::
	if (gripTarg < maxGripPos)
	{
		gripTarg := gripTarg + gripRate
		RunWait usccmd --servo %gripServo%`,%gripTarg%,,Hide
	}
	return

;Move Grip Close (Toward Min)
	!f::
	if (gripTarg > minGripPos)
	{
		gripTarg := gripTarg - gripRate
		RunWait usccmd --servo %gripServo%`,%gripTarg%,,Hide
	}
	return